package com.team622.shop.user.service.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.team622.shop.common.PageResult;
import com.team622.shop.common.Result;
import com.team622.shop.user.model.dto.MemberInfoPageQueryDTO;
import com.team622.shop.user.model.entity.MemberInfo;
import com.team622.shop.user.model.vo.MemberInfoPageVO;
import com.team622.shop.user.model.vo.MemberInfoVO;
import com.team622.shop.user.service.service.MemberInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author team622
 * @since 2025-07-15
 */
@Slf4j
@RestController
@RequestMapping("/memberInfo")
public class MemberInfoController {

    @Resource
    private MemberInfoService memberInfoService;

    @Operation(summary = "分页查询会员", description = "根据条件分页查询会员信息")
    @GetMapping("page")
    public PageResult<MemberInfoPageVO> page(
            @Parameter(description = "分页查询参数", required = true)
            @ModelAttribute MemberInfoPageQueryDTO memberPageQueryDTO) {
        IPage<MemberInfoPageVO> page = this.memberInfoService.getPage(memberPageQueryDTO);
        return PageResult.success(page);
    }

    @GetMapping("{id}")
    public Result<MemberInfo> get(@PathVariable("id") Long id) {
        MemberInfo memberInfo = this.memberInfoService.getById(id);
        return Result.success(memberInfo);
    }

    @Operation(summary = "编辑会员信息", description = "根据ID编辑会员信息")
    @PutMapping("")
    public Result<Object> update(@RequestBody MemberInfo memberInfo) {
        this.memberInfoService.updateById(memberInfo);
        return Result.success();
    }

    @Operation(summary = "批量删除会员", description = "根据ID列表批量删除会员信息")
    @DeleteMapping()
    public Result<Object> delete(@Parameter(description = "会员ID列表", required = true) @RequestBody List<Long> ids) {
        this.memberInfoService.removeBatchByIds(ids);
        return Result.success();
    }


    @Operation(summary = "获取管理员信息", description = "获取当前登录管理员的基本信息")
    @PostMapping("info")
    public Result<MemberInfoVO> info() {
        MemberInfoVO memberInfoVO = this.memberInfoService.info();
        return Result.success(memberInfoVO);
    }


}
